
using System.Diagnostics;
using System.Reflection;

namespace SharpTalk.Client.WpfApplication.ViewModels
{
    using Views;
    using System.Collections.ObjectModel;
    using Core;
    using System.Windows.Input;
    using Services;

    public class UserListViewModel : ControlViewModelBase<IUserListView>
    {
        private readonly ICommand _actionAddContactCommand = null;

        private ObservableCollection<User> _users;

        public UserListViewModel(IUserListView view) 
            : base(view)
        {
            view.DataContext = this;
        }

        public ObservableCollection<User> Users
        {
            get { return _users; }
            set
            {
                _users = value;
                NotifyPropertyChange(() => Users);
            }
        }

       
        public ICommand AddContactCommand
        {
            get { return _actionAddContactCommand ?? new BindableCommand<User>(OnAddContact); }
        }

        private void OnAddContact(User user)
        {
            if (ShouldTrace(TraceEventType.Verbose)) TraceMethodCall(MethodBase.GetCurrentMethod());
            if(user == null) return;

            if(!ApplicationServices.Current.Contacts.Contains(user))
                ApplicationServices.Current.Contacts.Add(user);
        }
        
    }
}